package com.weu.mapper;

import com.weu.bean.Car;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CarMapper {

    /**
     * 查询所有汽车
     *
     * @return
     */
    @Select("select * from ilmc_car")
    public List<Car> getAll();

    /**
     * 查询指定ID的汽车
     *
     * @param id
     * @return
     */
    @Select("select * from ilmc_car where car_id=#{id}")
    public Car getOne(int id);

    /**
     * @param id
     * @return
     */
    @Select("select * from ilmc_car where car_modelid=#{id}")
    public Car getByCarModelId(int id);

    /**
     * 根据汽车ID删除指定汽车
     *
     * @param id
     * @return
     */
    @Delete("delete from ilmc_car where car_id=#{id}")
    public int delById(int id);

    /**
     * 修改汽车型号
     *
     * @param car
     * @return
     */
    @Update("update ilmc_car set " +
            "car_modelid = #{carModelid}, " +
            "car_vendor = #{carVendor}, " +
            "car_energy_type =#{carEnergyType}, " +
            "car_emission_standard = #{carEmissionStandard}, " +
            "car_market_time = #{carMarketTime}, " +
            "car_max_power = #{carMaxPower}, " +
            "car_max_torque = #{carMaxTorque}, " +
            "car_max_speed = #{carMaxSpeed}, " +
            "car_fuel_consumption = #{carFuelConsumption} " +
            "where car_id = #{carId}")
    public int updateCar(Car car);


    /**
     * 保存汽车型号
     *
     * @param car
     * @return
     */
    @Insert("INSERT INTO ilmc_car(" +
            "car_modelid, car_vendor, car_energy_type, car_emission_standard, car_market_time, " +
            "car_max_power, car_max_torque, car_max_speed,  car_fuel_consumption) VALUES(" +
            "#{carModelid}, #{carVendor},  #{carEnergyType},  #{carEmissionStandard},  #{carMarketTime},  " +
            "#{carMaxPower}, #{carMaxTorque}, #{carMaxSpeed}, #{carFuelConsumption})")
    public int saveCar(Car car);
}
